package com.gxgeek.javabasic.concurrent.art.chapter04;

import sun.misc.Signal;

import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;

/**
 * 6-1
 */
public class MultiThread {

    public static void main(String[] args) {
        //  获取Java 管理的  MXBean
        ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
        // 不需要获取 同步的monitor和 synchronizer仅获取线程和线程的堆栈信息

        ThreadInfo[] threadInfos = threadMXBean.dumpAllThreads(false, false);
        // 遍历答应id 和名称
        for (ThreadInfo threadInfo : threadInfos) {
            System.out.println("[" + threadInfo.getThreadId() + "] " + threadInfo.getThreadName());
        }
//        out:
//        [5] Monitor Ctrl-Break
//        [4] Signal Dispatcher    分发处理发送JVM信号的线程
//        [3] Finalizer           调用对象finalize的线程
//        [2] Reference Handler   清除Reference的线程
//        [1] main                  主线程

    }
}
